home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software 2000
/
Software 2000 Volume 1 (Disc 1 of 2).iso
/
utilities
/
u035b.dms
/
u035b.adf
/
Requesters
/
Example9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-30
|
21KB
|
535 lines
/* Example9 */
/* This program will open a normal window which is connected to the */
/* Workbench Screen. The window will use all System Gadgets, and will */
/* close first when the user has selected the System gadget Close */
/* window. Inside the window we have activated an Application requester */
/* with three connecting gadgets. Two are Boolean gadgets ("OK and */
/* "CANCEL"), and one is a Proportional gadget. */
#include <intuition/intuition.h>
struct IntuitionBase *IntuitionBase;
/*****************************************/
/* THE PROPORTIONAL GADGET's STRUCTURES: */
/*****************************************/
/* The IntuiText structure for the proportional gadget: */
struct IntuiText prop_text=
{
1, /* FrontPen, colour register 1. */
0, /* BackPen, colour register 0. */
JAM1, /* DrawMode, draw the characters with colour 1, do not */
/* change the background. */
-65, 2, /* LeftEdge, TopEdge. */
NULL, /* ITextFont, use default font. */
"Colour:", /* IText, the text that will be printed. */
NULL, /* NextText, no other IntuiText structures. */
};
/* We need to declare an Image structure for the knob, but since */
/* Intuition will take care of the size etc of the knob, we do not need */
/* to initialize the Image structure: */
struct Image prop_image;
struct PropInfo prop_info=
{
FREEHORIZ| /* Flags, the knob should be moved horizontally, and */
AUTOKNOB, /* Intuition should take care of the knob image. */
0, /* HorizPot, start position of the knob. */
0, /* VertPot, 0 since we will not move the knob hor. */
MAXBODY * 1/16, /* HorizBody, 16 steps. */
0, /* VertBody, 0 since we will not move the knob hor. */
/* These variables are initialized and maintained by Intuition: */
0, /* CWidth */
0, /* CHeight */
0, 0, /* HPotRes, VPotRes */
0, /* LeftBorder */
0 /* TopBorder */
};
struct Gadget prop_gadget=
{
NULL, /* NextGadget, no more gadgets in the list. */
80, /* LeftEdge, 80 pixels out. */
30, /* TopEdge, 30 lines down. */
189, /* Width, 189 pixels wide. */
12, /* Height, 12 pixels lines heigh. */
GADGHCOMP, /* Flags, complement the colours. */
GADGIMMEDIATE| /* Activation, our program will recieve a message */
RELVERIFY, /* when the user has selected this gadget, and when */
/* the user has released it. */
PROPGADGET, /* GadgetType, a Proportional gadget. */
(APTR) &prop_image,/* GadgetRender, a pointer to our Image structure. */
/* (Intuition will take care of the knob image) */
/* (See chapter 3 GRAPHICS for more information) */
NULL, /* SelectRender, NULL since we do not supply the */
/* gadget with an alternative image. */
&prop_text, /* GadgetText, colour. */
NULL, /* MutualExclude, no mutual exclude. */
(APTR) &prop_info, /* SpecialInfo, pointer to a PropInfo structure. */
0, /* GadgetID, no id. */
NULL /* UserData, no user data connected to the gadget. */
};
/*******************************/
/* THE OK GADGET's STRUCTURES: */
/*******************************/
/* The coordinates for the OK box: */
SHORT ok_border_points[]=
{
0, 0, /* Start at position (0,0) */
22, 0, /* Draw a line to the right to position (22,0) */
22, 10, /* Draw a line down to position (22,10) */
0, 10, /* Draw a line to the left to position (0,10) */
0, 0 /* Finish of by drawing a line up to position (0,0) */
};
/* The Border structure: */
struct Border ok_border=
{
0, 0, /* LeftEdge, TopEdge. */
1, /* FrontPen, colour register 1. */
0, /* BackPen, for the moment unused. */
JAM1, /* DrawMode, draw the lines with colour 1. */
5, /* Count, 5 pair of coordinates in the array. */
ok_border_points, /* XY, pointer to the array with the coord. */
NULL, /* NextBorder, no other Border structures are connected. */
};
/* The IntuiText structure: */
struct IntuiText ok_text=
{
1, /* FrontPen, colour register 1. */
0, /* BackPen, not used since JAM1. */
JAM1, /* DrawMode, draw the characters with colour 1, do not */
/* change the background. */
4, 2, /* LeftEdge, TopEdge. */
NULL, /* ITextFont, use default font. */
"OK", /* IText, the text that will be printed. */
NULL, /* NextText, no other IntuiText structures are connected. */
};
struct Gadget ok_gadget=
{
&prop_gadget, /* NextGadget, linked to the Proportional gadget. */
14, /* LeftEdge, 14 pixels out. */
47, /* TopEdge, 47 lines down. */
23, /* Width, 23 pixels wide. */
11, /* Height, 11 pixels lines heigh. */
GADGHCOMP, /* Flags, when this gadget is highlighted, the gadget */
/* will be rendered in the complement colours. */
/* (Colour 0 (00) will be changed to colour 3 (11) */
/* (Colour 1 (01) - " - 2 (10) */
/* (Colour 2 (10) - " - 1 (01) */
/* (Colour 3 (11) - " - 0 (00) */
GADGIMMEDIATE| /* Activation, our program will recieve a message when */
RELVERIFY| /* the user has selected this gadget, and when the user */
/* has released it. */
ENDGADGET, /* When the user has selected this gadget, the */
/* requester is satisfied, and is deactivated. */
/* IMPORTANT! At least one gadget per requester */
/* must have the flag ENDGADGET set. If not, the */
/* requester would never be deactivated! */
BOOLGADGET| /* GadgetType, a Boolean gadget which is connected to */
REQGADGET, /* a requester. IMPORTANT! Every gadget which is */
/* connectd to a requester must have the REQGADGET flsg */
/* set in the GadgetType field. */
(APTR) &ok_border, /* GadgetRender, a pointer to our Border struc. */
NULL, /* SelectRender, NULL since we do not supply the gadget */
/* with an alternative image. (We complement the */
/* colours instead) */
&ok_text, /* GadgetText, a pointer to our IntuiText structure. */
/* (See chapter 3 GRAPHICS for more information) */
NULL, /* MutualExclude, no mutual exclude. */
NULL, /* SpecialInfo, NULL since this is a Boolean gadget. */
/* (No binary mask) */
0, /* GadgetID, no id. */
NULL /* UserData, no user data connected to the gadget. */
};
/***********************************/
/* THE CANCEL GADGET's STRUCTURES: */
/***********************************/
/* The coordinates for the CANCEL box: */
SHORT cancel_border_points[]=
{
0, 0, /* Start at position (0,0) */
54, 0, /* Draw a line to the right to position (54,0) */
54, 10, /* Draw a line down to position (54,10) */
0, 10, /* Draw a line to the left to position (0,10) */
0, 0 /* Finish of by drawing a line up to position (0,0) */
};
/* The Border structure: */
struct Border cancel_border=
{
0, 0, /* LeftEdge, TopEdge. */
1, /* FrontPen, colour register 1. */
0, /* BackPen, for the moment unused. */
JAM1, /* DrawMode, draw the lines with colour 1. */
5, /* Count, 5 pair of coordinates in the array. */
cancel_border_points, /* XY, pointer to the array with the coord. */
NULL, /* NextBorder, no other Border structures are connected. */
};
/* The IntuiText structure: */
struct IntuiText cancel_text=
{
1, /* FrontPen, colour register 1. */
0, /* BackPen, not used since JAM1. */
JAM1, /* DrawMode, draw the characters with colour 1, do not */
/* change the background. */
4, 2, /* LeftEdge, TopEdge. */
NULL, /* ITextFont, use default font. */
"CANCEL", /* IText, the text that will be printed. */
NULL, /* NextText, no other IntuiText structures are connected. */
};
struct Gadget cancel_gadget=
{
&ok_gadget, /* NextGadget, linked to the OK gadget. */
214, /* LeftEdge, 214 pixels out. */
47, /* TopEdge, 47 lines down. */
55, /* Width, 55 pixels wide. */
11, /* Height, 11 pixels lines heigh. */
GADGHCOMP, /* Flags, when this gadget is highlighted, the gadget */
/* will be rendered in the complement colours. */
/* (Colour 0 (00) will be changed to colour 3 (11) */
/* (Colour 1 (01) - " - 2 (10) */
/* (Colour 2 (10) - " - 1 (01) */
/* (Colour 3 (11) - " - 0 (00) */
GADGIMMEDIATE| /* Activation, our program will recieve a message when */
RELVERIFY| /* the user has selected this gadget, and when the user */
/* has released it. */
ENDGADGET, /* When the user has selected this gadget, the */
/* requester is satisfied, and is deactivated. */
/* IMPORTANT! At least one gadget per requester */
/* must have the flag ENDGADGET set. If not, the */
/* requester would never be deactivated! */
BOOLGADGET| /* GadgetType, a Boolean gadget which is connected to */
REQGADGET, /* a requester. IMPORTANT! Every gadget which is */
/* connectd to a requester must have the REQGADGET flsg */
/* set in the GadgetType field. */
(APTR) &cancel_border, /* GadgetRender, a pointer to our Border struc. */
NULL, /* SelectRender, NULL since we do not supply the gadget */
/* with an alternative image. (We complement the */
/* colours instead) */
&cancel_text, /* GadgetText, a pointer to our IntuiText structure. */
/* (See chapter 3 GRAPHICS for more information) */
NULL, /* MutualExclude, no mutual exclude. */
NULL, /* SpecialInfo, NULL since this is a Boolean gadget. */
/* (No binary mask) */
0, /* GadgetID, no id. */
NULL /* UserData, no user data connected to the gadget. */
};
/************************************************************************/
/* Note: */
/* Remember that every gadget which is connected to a requester must */
/* have the flag REQGADGET set in the GadgetType field. Remember also */
/* that at least one gadget per requester must have the ENDGADGET flag */
/* set in the Activation field. */
/* In this example we have three gadgets connected to the requester. */
/* All of them has the REQGADGET flag set, and the OK and CANCEL gadget */
/* has also the ENDGADGET flag set. */
/************************************************************************/
/************************************/
/* THE BORDER AROUND THE REQUESTER: */
/************************************/
/* The coordinates for the box around the requester: */
SHORT requester_border_points[]=
{
0, 0, /* Start at position (0,0) */
282, 0, /* Draw a line to the right. */
282, 64, /* Draw a line down. */
0, 64, /* Draw a line to the left. */
0, 0 /* Finish of by drawing a line up to position (0,0) */
};
/* The Border structure for the requester: */
struct Border requester_border=
{
0, 0, /* LeftEdge, TopEdge. */
1, /* FrontPen, colour register 1. */
0, /* BackPen, for the moment unused. */
JAM1, /* DrawMode, draw the lines with colour 1. */
5, /* Count, 5 pair of coordinates in the array. */
requester_border_points, /* XY, pointer to the array with the coord. */
NULL, /* NextBorder, no other Border structures are connected. */
};
/**********************************/
/* THE TEXT INSIDE THE REQUESTER: */
/**********************************/
/* The IntuiText structure used to print some text inside the requester: */
struct IntuiText requester_text=
{
1, /* FrontPen, colour register 1. */
0, /* BackPen, unused since JAM1. */
JAM1, /* DrawMode, draw the characters with colour 1, do not */
/* change the background. */
14, 8, /* LeftEdge, TopEdge. */
NULL, /* ITextFont, use default font. */
"Please set the colour value:", /* IText, the text. */
NULL, /* NextText, no other IntuiText structures are connected. */
};
/****************************/
/* THE REQUESTER STRUCTURE: */
/****************************/
struct Requester my_requester=
{
NULL, /* OlderRequester, used by Intuition. */
40, 20, /* LeftEdge, TopEdge, 40 pixels out, 20 lines down. */
283, 65, /* Width, Height, 283 pixels wide, 65 lines high. */
0, 0, /* RelLeft, RelTop, Since POINTREL flag is not set, */
/* Intuition ignores these values. */
&cancel_gadget, /* ReqGadget, pointer to the first gadget. */
&requester_border, /* ReqBorder, pointer to a Border structure. */
&requester_text, /* ReqText, pointer to a IntuiText structure. */
NULL, /* Flags, no flags set. */
2, /* BackFill, draw everything on a black background. */
NULL, /* ReqLayer, used by Intuition. Set to NULL. */
NULL, /* ReqPad1, used by Intuition. Set to NULL. */
NULL, /* ImageBMap, no predrawn Bitmap. Set to NULL. */
/* (The PREDRAWN flag was not set) */
NULL, /* RWindow, used by Intuition. Set to NULL. */
NULL /* ReqPad2, used by Intuition. Set to NULL. */
};
/* Declare a pointer to a Window structure: */
struct Window *my_window;
/* Declare and initialize your NewWindow structure: */
struct NewWindow my_new_window=
{
0, /* LeftEdge x position of the window. */
0, /* TopEdge y positio of the window. */
640, /* Width 640 pixels wide. */
200, /* Height 200 lines high. */
0, /* DetailPen Text should be drawn with colour reg. 0 */
1, /* BlockPen Blocks should be drawn with colour reg. 1 */
CLOSEWINDOW| /* IDCMPFlags The window will give us a message if the */
/* user has selected the Close window gad, */
GADGETDOWN| /* or a gadget has been pressed on, or */
GADGETUP| /* a gadge has been released. */
REQSET| /* Send a message also if a requester has */
REQCLEAR, /* been activated or deactivated. */
SMART_REFRESH| /* Flags Intuition should refresh the window. */
WINDOWCLOSE| /* Close Gadget. */
WINDOWDRAG| /* Drag gadget. */
WINDOWDEPTH| /* Depth arrange Gadgets. */
WINDOWSIZING| /* Sizing Gadget. */
ACTIVATE, /* The window should be Active when opened. */
NULL, /* FirstGadget No gadget connected to this window. */
NULL, /* CheckMark Use Intuition's default CheckMark. */
"The Window", /* Title Title of the window. */
NULL, /* Screen Connected to the Workbench Screen. */
NULL, /* BitMap No Custom BitMap. */
140, /* MinWidth We will not allow the window to become */
50, /* MinHeight smaller than 140 x 50, and not bigger */
300, /* MaxWidth than 300 x 200. */
200, /* MaxHeight */
WBENCHSCREEN /* Type Connected to the Workbench Screen. */
};
main()
{
/* Boolean variable used for the while loop: */
BOOL close_me;
/* Declare a variable in which we will store the IDCMP flag: */
ULONG class;
/* Declare a variable in which we will store the address of the */
/* gadget which sent the message: */
APTR address;
/* Declare a pointer to an IntuiMessage structure: */
struct IntuiMessage *my_message;
/* We use this variable to check if the requester has ben activated */
/* or not: */
BOOL result;
/* Before we can use Intuition we need to open the Intuition Library: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
exit(); /* Could NOT open the Intuition Library! */
/* We will now try to open the window: */
my_window = (struct Window *) OpenWindow( &my_new_window );
/* Have we opened the window succesfully? */
if(my_window == NULL)
{
/* Could NOT open the Window! */
/* Close the Intuition Library since we have opened it: */
CloseLibrary( IntuitionBase );
exit();
}
/* We have opened the window, and everything seems to be OK. */
/* We will now try to activate the requester: */
result=Request( &my_requester, my_window );
if( !result ) /* !result is the same thing as result==FALSE */
{
/* Intuition could not activate the requester! */
/* In this case we do not need to quit since it does not matter if */
/* the requester was activated or not. I just wanted to show how */
/* you can check if you have opened or not the requester. */
printf("Could not activate the requester!\n");
}
else
{
/* Intuition could open the requester! */
printf("Try to close the window!\n");
}
close_me = FALSE;
/* Stay in the while loop until the user has selected the Close window */
/* gadget. However, in this example the user first need to deactivate */
/* the requester before he can select the Close window gadget: */
while( !close_me )
{
/* Wait until we have recieved a message: */
Wait( 1 << my_window->UserPort->mp_SigBit );
/* As long as we collect messages sucessfully: */
while(my_message=(struct IntuiMessage *) GetMsg(my_window->UserPort))
{
/* After we have collected the message we can read it, and save any */
/* important values which we maybe want to check later: */
/* Store the IDCMP flag: */
class = my_message->Class;
/* Store the address: */
address = my_message->IAddress;
/* After we have read it we reply as fast as possible: */
/* REMEMBER! Do never try to read a message after you have replied! */
/* Some other process has maybe changed it. */
ReplyMsg( my_message );
/* Check which IDCMP flag was sent: */
switch( class )
{
case CLOSEWINDOW: /* The user selected the Close window gadget! */
close_me=TRUE;
break;
case GADGETDOWN: /* The user has pressed on a gadget. */
if( address == (APTR) &ok_gadget )
printf("The user pressed on the OK gadget!\n");
if( address == (APTR) &cancel_gadget )
printf("The user pressed on the CANCEL gadget!\n");
if( address == (APTR) &prop_gadget )
printf("The user selected the Proportional gadget!\n");
break;
case GADGETUP: /* The user has released a gadget. */
if( address == (APTR) &ok_gadget )
printf("The user released the OK gadget!\n");
if( address == (APTR) &cancel_gadget )
printf("The user released the CANCEL gadget!\n");
if( address == (APTR) &prop_gadget )
{
printf("The user released the Proportional gadget!\n");
/* Print out the colour value: */
printf("Colour= %1.0f\n\n", (float) prop_info.HorizPot
/ MAXPOT*16);
}
break;
case REQSET: /* Requester activated. */
printf("Requester activated!\n");
break;
case REQCLEAR: /* Requester deactivated. */
printf("Requester deactivated!\n");
printf("You can now close the window.\n");
break;
}
}
}
/* Print out the colour value: */
printf( "Colour= %1.0f\n\n", (float) prop_info.HorizPot / MAXPOT*16 );
/* We should always close the windows we have opened before we leave: */
CloseWindow( my_window );
/* Close the Intuition Library since we have opened it: */
CloseLibrary( IntuitionBase );
/* THE END */
}